import axios from 'axios'
import Vue from 'vue'

const RNTY_BASE_URL = 'http://192.168.3.13:9001/'
const RNTY_AUTH_BASE_URL = 'http://192.168.3.13:9000/'
const CLIENT_ID = 3
const CLIENT_SECRET = 'LObGcz7I1YcTC4Ze7wczr4ACmf81uLDY'
const _this = Vue.prototype

function request ({method = 'get', baseURL, url, param, data, contenType = 'application/x-www-form-urlencoded'}) {
  if (method === 'get') {
    return axios({
      method: method,
      baseURL: baseURL,
      url: url,
      param: param,
      transformRequest: [function (data) {
        // Do whatever you want to transform the data
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        return ret
      }]
    })
  } else {
    return axios({
      method: method,
      baseURL: baseURL,
      headers: {'Content-Type': contenType},
      url: url,
      param: param,
      data: data,
      transformRequest: [function (data) {
        // Do whatever you want to transform the data
        let ret = ''
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        return ret
      }]
    })
  }
}

export default {
  RNTY_BASE_URL,
  RNTY_AUTH_BASE_URL,
  CLIENT_ID,
  CLIENT_SECRET,
  request
}
